<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script src="../js/vue.js"></script>

  <div id="app">
    书名: <input type="text"  v-model="name">
    作者: <input type="text" v-model="author" >
    <button @click="add">添加</button>
    <ul>
      <li v-for="(item, index) in booksList" :key="item.id">
        <span>{{item.name}}</span>
        <span>{{item.author}}</span>
        <button @click="remove(item.id)">删除</button>
      </li>
    </ul>
  </div>

  <script>
    new Vue({
      el:'#app',
      data:{
        name:'',
        author:'',
        booksList: [
          { id: 1, name: '《红楼梦》', author: '曹雪芹' },
          { id: 2, name: '《西游记》', author: '吴承恩' },
          { id: 3, name: '《水浒传》', author: '施耐庵' },
          { id: 4, name: '《三国演义》', author: '罗贯中' }
        ]
      },
      methods: {
        add(){
          this.booksList.push({
            id: this.booksList.length + 1,
            name:this.name,
            author:this.author
          })
        },
        remove(index){
          this.booksList =this.booksList.filter(item=>item.id != index)
        }
      },
    })
  </script>
</body>
</html>